package com.qianxunclub.chapter14;


import java.io.FileInputStream;
import java.io.InputStream;
import org.apache.poi.util.StringUtil;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * @author zhangbin
 */
public class Application {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = new FileInputStream("/Users/zhangbin/Downloads/test.xlsx");
        XSSFWorkbook book = new XSSFWorkbook(inputStream);
        XSSFSheet sheet = book.getSheetAt(0);
        int rowNum = sheet.getLastRowNum() + 1;
        for (int i = 0; i < rowNum; i++) {
            if (sheet.getRow(i) != null) {
                int coloumNum = sheet.getRow(i).getPhysicalNumberOfCells();
                for (int j = 0; j < coloumNum; j++) {
                    XSSFCell cell = sheet.getRow(i).getCell(j);
                    if (cell != null) {
                        String v = cell.getRawValue();
                        System.out.print(v + "\t");
                    } else {
                        System.out.print("第" + i + "行，第" + j + "列没有数据\t");
                    }
                }
                System.out.print("\n");
            } else {
                System.out.println("第" + i + "行是空行");
            }
        }
    }

}
